package com.example.hello.client.Paragraph;

import com.example.hello.BootstrapParagraph;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapParagraph.class)
public class BootstrapParagraphConnector extends AbstractComponentConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapParagraph.class);
    }

    @Override
    public BootstrapParagraphState getState() {
        return (BootstrapParagraphState) super.getState();
    }

    @Override
    public VBootstrapParagraph getWidget() {
        return (VBootstrapParagraph) super.getWidget();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapParagraphState state = getState();

        VBootstrapParagraph paragraph = getWidget();

        paragraph.setText(state.getText());
        paragraph.setAlignment(state.getAlignment());
        paragraph.setMargin(state.getMargin());
    }

}